package com.k.base.jdk.proxy.demo2;

import com.k.base.jdk.proxy.demo2.frm.ProxyUtils;
import com.k.base.jdk.proxy.demo2.frm.ProxyAction;

/**
 * JDK 动态代理
 * @author k
 */
public class Test {
    public static void main(String[] args) {
        // origin object must be interface impl object
        Car carOrigin = new BmwCar();

        // 切面行为
        ProxyAction noticeAction = new NoticeProxyAction();

        // 返回代理对象 proxy object com.sun.proxy.$Proxy0
        Car carProxy = (Car)ProxyUtils.proxyInstance1(Car.class.getClassLoader(), new Class[]{Car.class},carOrigin,noticeAction);

        String brand = carProxy.brand();
        System.out.println("brand:"+brand);
        System.out.println("----------------");
        String n = carProxy.number("123");
        System.out.println(n);

    }
}
